#ifndef CAMERAPAGE_H
#define CAMERAPAGE_H
#include <QWidget>
#include <QDebug>
#include <QPushButton>
#include <QLabel>
#include <QBoxLayout>
#include <QLayout>
#include <QCamera>
#include <QCameraInfo>
#include <QAudioDeviceInfo>
#include <QPixmap>
#include <QStackedLayout>
#include <QMediaServiceCameraInfoInterface>
#include <QMediaService>
#include <QImage>
#include <QMessageBox>
#include <QTimer>
#include <QTime>
#include <QCameraCaptureBufferFormatControl>
#include <QCameraImageCapture>
#include <QStatusBar>
#include <QMediaRecorder>
#include <QFileSystemWatcher>
#include <QStackedWidget>
#include <QApplication>
#include <QFileInfoList>
#include <QDBusInterface>
#include <QThread>
#include "currentdeviceinfo.h"
#include "button.h"
#include "VideoDisplay.h"
#include "kylincamera_global.h"
#include "KylinCamera.h"
#include "delaywdiget.h"
#include "aboutwidget.h"
#include "camerakeepalive.h"

class CameraPage : public QStackedWidget
{
    Q_OBJECT
public:
    CameraPage(QWidget *parent = 0);
    ~CameraPage();
    QImage image;
    //图像右上角按钮

    QHBoxLayout *hlayout;
    QVBoxLayout *vlayout;
    QVBoxLayout *vlayout_out;
    QStackedLayout *layout;
    QCameraInfo *camerainfo;
    QHBoxLayout *recordLayout;
    QHBoxLayout *buttomLayout;
    QHBoxLayout *recorderWidgetLayout;
    //摄像头信息
    KylinCamera *camera = nullptr;
    VideoCapture *video;
    VideoDisplay *videoDisplay;
    QFileInfoList video_info;

    QList<QCameraInfo> camerainfo_list;
    QCameraInfo camera_info;
    Button *btnPage = nullptr;

    //倒计时
    QLabel *dead_time;
    QTimer *time;

    QWidget *widgetDisplay;
    QWidget *timeLabel;
    QLabel *recorder_time_label;
    QTimer * recorder_time;
    DelayWdiget *delayWidget;
    QWidget *recorder;
    QWidget *recorderWidget;
    QWidget *recorderWidgetWin;
    QStackedWidget *buttom;
    QWidget *buttomWidget;
    int hour = 0;
    int min = 0;
    int sec = 0;
    //未发现摄像头
    QLabel *No_device_lab;
    QLabel *No_device_lab_s;
    QLabel *No_device_icon;

    //静态全局变量保存摄像头的状态，当前摄像头状态和现有的设备列表
    static bool has_device;
    static char* current_indevice;
    static QList<QCameraInfo> *cameras;
    static QList<QAudioDeviceInfo> *audios;
    static QGSettings *m_GsettingThemeData;
    QDBusInterface *server;
    quint32 arg_0; //用来保存返回值
    void resetCamera(KylinCameraInfo);

protected:
//    virtual bool eventFilter(QObject *watched, QEvent *event);
    virtual void paintEvent(QPaintEvent *);
signals:
    //设备被拔出
    void device_pull_out();

public slots:
    //未发现设备
    void displayCameraError();
    //时间信号
    void timeEvent();
    //打开摄像头
    void creatCameraPage(const char *);
    //设置设备参数
    void camera_set_param(KylinCameraInfo *);
    //更改摄像头设备
    void change_device(const char *);
    //设置分辨率
    void change_resolution(QPair<uint,uint>);
//    //改变分辨率后，预览页面更改窗口比例
//    void changeWindowScale();
    //返回当前使用的设置
    void stopCamera();
    void startExistCamera(KylinCameraInfo cameraInfo);
    KylinCameraInfo getCameraInfo();
protected:

private:
    //创建显示界面
    //未发现摄像头的两个组件
    QWidget *widget1;
    QWidget *widget2;
    QWidget *widget3;
    //未发现摄像头界面
    QWidget *No_device;
    //摄像头显示界面
    QWidget *cameraViewPage;
    QLabel *lab;

    void layout_operation();
    void drawGrid(QPainter *);
    void setNoDevice();
    void setCameraViewPage();
    void timeoutEvent(KylinCameraInfo);
    //
    CameraKeepAlive *perSec;
    QTimer *secTimer;
    int heartBeatsNum;
    KylinCameraInfo m_camInfo;
    void dealSystemGsettingChange(const QString);
    void refreshThemeBySystemConf();
    void initAudioDevice();
};

#endif // CAMERAPAGE_H
